package model;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import dao.GetCnn;
import entity.Nhanvien;


public class NhanvienModel {
	public boolean checknv(String manhanvien) throws SQLException{
		Connection cnn = GetCnn.getCnn();
		Statement stat = cnn.createStatement();
		String sSQL = "select MANHANVIEN,MATKHAU from NHANVIEN where MANHANVIEN ='"+manhanvien+"'";
		ResultSet rs = stat.executeQuery(sSQL);
		if(rs.next()){
			return true;
		}
		else
			return false;
	}
	public List<Nhanvien> getnv(String strSearch) throws SQLException{
		List<Nhanvien> list = new ArrayList<Nhanvien>();
		Connection cnn = GetCnn.getCnn();
		Statement stat = cnn.createStatement();
		ResultSet rs = stat.executeQuery(strSearch);
		while(rs.next()){
			Nhanvien entity = new Nhanvien();
			entity.setManhanvien(rs.getString("MANHANVIEN"));
			entity.setTennhanvien(rs.getString("TENNHANVIEN"));
			entity.setMatkhau(rs.getString("MATKHAU"));
			entity.setDiachi(rs.getString("DIACHI"));
			entity.setDienthoai(rs.getString("DIENTHOAI"));
			entity.setLuong(rs.getInt("LUONG"));
			entity.setNgayvl(rs.getString("NGAYVL"));
			list.add(entity);
		}
		return list;
	}

}
